import { queryForList, deleteData, getById, createOrUpdate } from '@/api/system/entityPropertyApi'

const state = {
}

const mutations = {
}

const actions = {
    queryForList({ commit }, entityProperty) {
        const { entityId, title, fieldName, pager } = entityProperty
        return new Promise((resolve, reject) => {
            queryForList({ entityId, title, fieldName, pager }).then(response => {
                const { data } = response
                resolve(data)
            }).catch(error => {
                reject(error)
            })
        })
    },

    createOrUpdate({ commit }, entityProperty) {
        const { id, entityId, title, fieldName, fieldType, required, defaultValue, fieldLength, description } = entityProperty
        return new Promise((resolve, reject) => {
            createOrUpdate({ id, entityId, title, fieldName, fieldType, required, defaultValue, fieldLength, description }).then(response => {
                const { data } = response
                resolve(data)
            }).catch(error => {
                reject(error)
            })
        })
    },

    deleteData({ commit }, dataId) {
        return new Promise((resolve, reject) => {
            deleteData(dataId).then(response => {
                const { data } = response
                resolve(data)
            }).catch(error => {
                reject(error)
            })
        })
    },

    getById({ commit }, dataId) {
        return new Promise((resolve, reject) => {
            getById(dataId).then(response => {
                const { data } = response
                resolve(data)
            }).catch(error => {
                reject(error)
            })
        })
    }
}

export default {
    namespaced: true,
    state,
    mutations,
    actions
}

